#include <iostream>
#include <string.h>
using std::cout;
using std::endl;

class Computer{

private:
    char *_brand;
    int _price;

public:
    
    //浅拷贝
//    Computer(const char *brand,int price)
//    :_brand(brand)
//    ,_price(price){
//        cout << "call constructor" << endl;
//    }
    
    //深拷贝
    Computer(const char *brand,int price)
    :_brand(new char[strlen(brand)+1]())
    ,_price(price){
        strcpy(_brand,brand);
        cout << "call constructor" << endl;
    }

    void print(){
        cout << "brand=" << _brand << endl
             << "price=" << _price << endl;
    }

    ~Computer(){
        cout << "call deconstructor" << endl;
        if(_brand!=NULL){
            delete[] _brand;
            _brand=NULL;
        }
    }

    Computer(const Computer &rhs)
    :_brand(new char[strlen(rhs._brand)+1]())
     ,_price(rhs._price){
         strcpy(_brand,rhs._brand);
         cout << "call copy constrctor" << endl;
     }
};

int main()
{
    Computer c("Apple",12000);
    Computer c1(c);
    c.print();
    c1.print();
    return 0;
}